package com.data.modules.openapi.controller;

import com.alibaba.fastjson.JSONObject;
import com.data.common.aspect.annotation.AutoLog;
import com.data.modules.openapi.config.OpenApiConfig;
import com.data.modules.openapi.service.IOpenApiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 *  OpenApi 统计接口路径
 *
 * @author: cmg
 * @since: 2022-04-06 18:34
 **/

@Api(tags="OpenApi")
@Controller
@RequestMapping("/openapi")
@Slf4j
public class OpenApiController {
    @Autowired
    private IOpenApiService openApiService;


    /**
     * 仅支持 X-App-Key 验证
     * @param request
     * @return
     */
    @AutoLog(value = "openapi-v0")
    @ApiOperation(value="openapi-统一接口", notes="openapi-统一接口")
    @RequestMapping(value = "/v0")
    public Object openapiV0(HttpServletRequest request) {
        log.info("===X-App-Key===>{},==X-Uid-Time====>{},==X-Path=====>{}",
                JSONObject.toJSONString(request.getHeader("X-App-Key")),
                JSONObject.toJSONString(request.getHeader("X-Uid-Time")),
                JSONObject.toJSONString(request.getHeader("X-Path")));
        String path = openApiService.openapiV0(request);
        log.info("v0 OpenApi==统一通行接口检查===>{}",path);
        return "forward:"+path;
    }


    @AutoLog(value = "openapi-v1")
    @ApiOperation(value="openapi-统一接口", notes="openapi-统一接口")
    @RequestMapping(value = "/v1")
    public Object openapiV1(HttpServletRequest request) {
        log.info("===X-App-Key===>{},==X-Uid-Time====>{},==X-Path=====>{}",
                JSONObject.toJSONString(request.getHeader("X-App-Key")),
                JSONObject.toJSONString(request.getHeader("X-Uid-Time")),
                JSONObject.toJSONString(request.getHeader("X-Path")));
        String path = openApiService.openapiV1(request);
        log.info("OpenApi==统一通行接口检查===>{}",path);
        return "forward:"+path;
    }



}
